package com.dksidana.java.jdbc;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import com.dksidana.java.jdbc.core.QueryRunner;
import com.dksidana.java.jdbc.core.ResultSetHandler;

public class DataSourceWrapper implements QueryRunner{
	DataSource dataSource;
	public DataSourceWrapper(DataSource dataSource) {
		this.dataSource=dataSource;
	}
	public <T> T executeQuery(String query, ResultSetHandler<T> rsh)
			throws SQLException {
		Connection connection= dataSource.getConnection();
		T t=null;
		try
		{
			t=JDBCUtils.executeQuery(connection, query, rsh);
		}
		finally
		{
			connection.close();
		}
		return t;
	}	
}
